﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foothill.Utils;
using Foothill.WF.Command;
using Foothill.WF.Core;
using GGFW.Entity.SystemManage;
using Foothill.Privilege;
using Foothill.Privilege.Entity;
using Foothill.Privilege.Utils;
using GGFW.BusinessLogic.SystemManage;

namespace GGFW.Command.SystemManage
{
    public class UserCommand : DispatchCommand
    {
        #region 更改用户密码
        /// <summary>
        /// 更改密码
        /// </summary>
        /// <param name="context">Http的特定信息，包含查询条件</param>
        /// <param name="requestType">请求提交方式</param>
        /// <param name="url">预留参数，暂未使用</param>
        /// <returns>返回结果集</returns>
        public ResultBase onUpdatePwd(HttpContext context, RequestType requestType, string url)
        {

            ResultBase result = null;
            try
            {
                string OldPwd = context.Request["OldPwd"];
                string NewPwd = context.Request["NewPwd"];
                System.Web.HttpContext hc = System.Web.HttpContext.Current;
                FoothillUser user = hc.Session[PublicConstants.SESSION_USER] as FoothillUser;

                if (user == null)
                {
                    result = new ResultBase();
                    result.Success = false;
                    result.Message = "登录已过期，请重新登录后再操作!";
                }
                else if (!user.Password.Equals(OldPwd))
                {
                    result = new ResultBase();
                    result.Success = false;
                    result.Message = "旧密码不正确!";
                }
                else
                {
                    using (UserControl control = new UserControl())
                    {
                        result = control.UpdatePwd(user.UserID, NewPwd);
                    }
                }
            }
            catch (Exception ex)
            {
                result = new ResultBase();
                result.Success = false;
                result.Message = ex.Message;
                log.Fatal(ex.Message);
            }
            return result;
        }
        #endregion
    }
}
